﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using FlexiCommerce.Components;
using FlexiCommerce.Collections;

namespace FlexiCommerce.Web.UI.WebControls
{
    public class ItemHierarchicalDataSourceView : HierarchicalDataSourceView
    {
        public ItemHierarchicalDataSourceView(IHierarchicalPersistenceItem parentItem)
        {
            this.parentItem = parentItem;
        }

        IHierarchicalPersistenceItem parentItem;

        public override IHierarchicalEnumerable Select()
        {
            if (parentItem == null)
            {
                return new ItemList<Category>(Find.Categories.Where(cat => cat.Parent == null).ToList());
            }
            else
            {
                return new ItemList(parentItem.Children as IEnumerable<PersistenceItem>); ;
            }
        }
    }
}
